var colorCustomize = new Array; //存储自定义颜色的数组。
var colorPreload;  //存储预加载颜色。
var colorSelect;   //存储当前选择的色块，用来对它进行改动

var totalColorUnitFrame; //颜色的对话框
var chooseColorFrame; //选择颜色库的对话框

var colorLibraryStart = 0; //可选颜色库中起始颜色库，用来滚动 

var colorFrameMoveTime;

var colorLibraryArrayNo = 0; //存储当前使用颜色库的序号。
var colorLibraryArray = new Array; //颜色库的数组
	
	colorLibraryArray[0] = [[249/255,1/255,1/255,1],
							 [248/255,148/255,0,1],
							 [249/255,188/255,144/255,1],
							 
							 [0,151/255,64/255,1],
							 [96/255,235/255,9/255,1],
							 [249/255,251/255,0,1],
							 
							 [0,59/255,247/255,1],
							 [0,163/255,248/255,1],
							 [159/255,199/255,248/255,1],
							 
							 [104/255,59/255,17/255,1],
							 [145/255,43/255,248/255,1],
							 [249/255,120/255,247/255,1],
							 
							 [0,0,0,1],
							 [128/255,128/255,128/255,1],
							 [249/255,251/255,248/255,1]
							 ];
	
	
	colorLibraryArray[1] = [[184/255,148/255,72/255,1],
							 [207/255,140/255,49/255,1],
							 [200/255,163/255,72/255,1],
							 
							 [120/255,139/255,145/255,1],
							 [144/255,163/255,169/255,1],
							 [144/255,180/255,192/255,1],
							 
							 [160/255,112/255,112/255,1],
							 [200/255,164/255,128/255,1],
							 [224/255,195/255,153/255,1],
							 
							 [80/255,32/255,56/255,1],
							 [104/255,49/255,72/255,1],
							 [120/255,72/255,88/255,1],
							 
							 [0,0,0,1],
							 [88/255,79/255,80/255,1],
							 [249/255,251/255,248/255,1]
							 ];
	
	colorLibraryArray[2] = [[128/255,52/255,56/255,1],
							 [176/255,96/255,89/255,1],
							 [216/255,152/255,143/255,1],
							 
							 [81/255,83/255,80/255,1],
							 [144/255,147/255,136/255,1],
							 [184/255,196/255,176/255,1],
							 
							 [32/255,44/255,40/255,1],
							 [56/255,65/255,64/255,1],
							 [80/255,92/255,88/255,1],
							 
							 [112/255,104/255,81/255,1],
							 [176/255,152/255,104/255,1],
							 [208/255,184/255,136/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];
	
	colorLibraryArray[3] = [[224/255,76/255,152/255,1],
							 [249/255,163/255,208/255,1],
							 [248/255,215/255,232/255,1],
							 
							 [240/255,205/255,1/255,1],
							 [248/255,236/255,0,1],
							 [244/255,251/255,160/255,1],
							 
							 [40/255,163/255,231/255,1],
							 [119/255,211/255,248/255,1],
							 [193/255,244/255,248/255,1],
							 
							 [136/255,53/255,223/255,1],
							 [193/255,125/255,248/255,1],
							 [240/255,204/255,248/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[4] = [[176/255,160/255,135/255,1],
							 [216/255,200/255,175/255,1],
							 [240/255,232/255,209/255,1],
							 
							 [56/255,43/255,24/255,1],
							 [96/255,80/255,54/255,1],
							 [136/255,120/255,95/255,1],
							 
							 [160/255,160/255,160/255,1],
							 [200/255,200/255,200/255,1],
							 [232/255,232/255,232/255,1],
							 
							 [41/255,43/255,40/255,1],
							 [80/255,80/255,80/255,1],
							 [120/255,120/255,120/255,1],
							 
							 [0,0,0,1],
							 [128/255,128/255,128/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[5] = [[72/255,27/255,144/255,1],
							 [112/255,52/255,208/255,1],
							 [168/255,129/255,248/255,1],
							 
							 [32/255,37/255,167/255,1],
							 [72/255,81/255,248/255,1],
							 [128/255,152/255,248/255,1],
							 
							 [15/255,120/255,168/255,1],
							 [48/255,183/255,247/255,1],
							 [127/255,233/255,247/255,1],
							 
							 [0,103/255,56/255,1],
							 [31/255,168/255,112/255,1],
							 [88/255,231/255,184/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[6] = [[104/255,92/255,16/255,1],
							 [184/255,145/255,16/255,1],
							 [232/255,203/255,73/255,1],
							 
							 [120/255,132/255,128/255,1],
							 [161/255,172/255,176/255,1],
							 [217/255,228/255,232/255,1],
							 
							 [64/255,36/255,24/255,1],
							 [112/255,68/255,41/255,1],
							 [168/255,120/255,97/255,1],
							 
							 [24/255,44/255,32/255,1],
							 [64/255,100/255,72/255,1],
							 [128/255,160/255,136/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[7] = [[184/255,60/255,8/255,1],
							 [248/255,117/255,1/255,1],
							 [248/255,200/255,136/255,1],
							 
							 [168/255,132/255,56/255,1],
							 [232/255,203/255,73/255,1],
							 [248/255,236/255,152/255,1],
							 
							 [0,111/255,104/255,1],
							 [40/255,171/255,137/255,1],
							 [169/255,216/255,184/255,1],
							 
							 [31/255,60/255,120/255,1],
							 [80/255,100/255,199/255,1],
							 [168/255,180/255,232/255,1],
							 
							 [0,0,0,1],
							 [122/255,122/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[8] = [[135/255,161/255,176/255,1],
							 [175/255,201/255,216/255,1],
							 [208/255,233/255,240/255,1],
							 
							 [24/255,44/255,55/255,1],
							 [55/255,81/255,96/255,1],
							 [95/255,121/255,136/255,1],
							 
							 [175/255,140/255,160/255,1],
							 [214/255,181/255,198/255,1],
							 [240/255,213/255,232/255,1],
							 
							 [56/255,28/255,40/255,1],
							 [95/255,60/255,80/255,1],
							 [135/255,100/255,120/255,1],
							 
							 [0,0,0,1],
							 [128/255,128/255,128/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[9] = [[144/255,1/255,143/255,1],
							 [241/255,0,231/255,1],
							 [248/255,140/255,241/255,1],
							 
							 [141/255,33/255,57/255,1],
							 [224/255,16/255,65/255,1],
							 [249/255,128/255,145/255,1],
							 
							 [168/255,88/255,1/255,1],
							 [240/255,125/255,0,1],
							 [248/255,192/255,105/255,1],
							 
							 [168/255,153/255,0,1],
							 [239/255,212/255,1/255,1],
							 [248/255,249/255,113/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[10] = [[144/255,4/255,127/255,1],
							 [225/255,1/255,136/255,1],
							 [249/255,136/255,224/255,1],
							 
							 [168/255,49/255,9/255,1],
							 [249/255,116/255,25/255,1],
							 [248/255,195/255,1/255,1],
							 
							 [64/255,131/255,25/255,1],
							 [120/255,196/255,0,1],
							 [209/255,251/255,1/255,1],
							 
							 [41/255,75/255,120/255,1],
							 [0,148/255,168/255,1],
							 [0,252/255,249/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[11] = [[128/255,48/255,49/255,1],
							 [177/255,104/255,9/255,1],
							 [184/255,148/255,88/255,1],
							 
							 [0,104/255,64/255,1],
							 [72/255,157/255,40/255,1],
							 [169/255,172/255,41/255,1],
							 
							 [40/255,79/255,144/255,1],
							 [56/255,119/255,160/255,1],
							 [112/255,156/255,191/255,1],
							 
							 [72/255,56/255,40/255,1],
							 [96/255,65/255,143/255,1],
							 [168/255,88/255,161/255,1],
							 
							 [0,0,0,1],
							 [129/255,131/255,128/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[12] = [[0,52/255,73/255,1],
							 [0,119/255,73/255,1],
							 [0,172/255,88/255,1],
							 
							 [0,148/255,88/255,1],
							 [8/255,163/255,121/255,1],
							 [96/255,171/255,16/255,1],
							 
							 [72/255,132/255,143/255,1],
							 [111/255,180/255,177/255,1],
							 [184/255,212/255,233/255,1],
							 
							 [224/255,228/255,240/255,1],
							 [224/255,245/255,240/255,1],
							 [249/255,251/255,248/255,1],
							 
							 [160/255,64/255,16/255,1],
							 [207/255,140/255,49/255,1],
							 [200/255,163/255,72/255,1]
							 ];

	colorLibraryArray[13] = [[153/255,80/255,48/255,1],
							 [216/255,140/255,80/255,1],
							 [248/255,180/255,145/255,1],
							 
							 [57/255,31/255,16/255,1],
							 [111/255,65/255,32/255,1],
							 [192/255,156/255,96/255,1],
							 
							 [96/255,65/255,143/255,1],
							 [72/255,87/255,168/255,1],
							 [56/255,111/255,88/255,1],
							 
							 [128/255,48/255,49/255,1],
							 [200/255,64/255,64/255,1],
							 [249/255,120/255,0,1],
							 
							 [0,0,0,1],
							 [104/255,113/255,112/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[14] = [[80/255,20/255,56/255,1],
							 [160/255,45/255,112/255,1],
							 [232/255,117/255,184/255,1],
							 
							 [72/255,52/255,25/255,1],
							 [161/255,121/255,72/255,1],
							 [224/255,188/255,112/255,1],
							 
							 [24/255,64/255,72/255,1],
							 [63/255,129/255,145/255,1],
							 [112/255,188/255,224/255,1],
							 
							 [56/255,28/255,79/255,1],
							 [120/255,68/255,168/255,1],
							 [185/255,120/255,224/255,1],
							 
							 [0,0,0,1],
							 [121/255,123/255,120/255,1],
							 [249/255,251/255,248/255,1]
							 ];

	colorLibraryArray[15] = [[248/255,105/255,1/255,1],
							 [248/255,164/255,40/255,1],
							 [248/255,205/255,113/255,1],
							 
							 [56/255,203/255,1/255,1],
							 [168/255,244/255,32/255,1],
							 [248/255,252/255,113/255,1],
							 
							 [0,143/255,248/255,1],
							 [104/255,195/255,248/255,1],
							 [183/255,228/255,247/255,1],
							 
							 [185/255,120/255,40/255,1],
							 [216/255,116/255,248/255,1],
							 [249/255,184/255,224/255,1],
							 
							 [0,0,0,1],
							 [128/255,128/255,128/255,1],
							 [249/255,251/255,248/255,1]
							 ];
	
//-------------------------------------------------------------
//创建一个全局的默认颜色指示色块
dialog.createColorExample = function(){
	var colorExampleBgColor = new Array;
	colorExampleBgColor[0] = [
								defultValue.red,
								defultValue.green,
								defultValue.blue,
								defultValue.alpha];
	colorExampleBgColor[1] = 75;
	colorExampleBgColor[2] = 75;
	
	var colorExampleBgColorActivtion = new Array;
	colorExampleBgColorActivtion["activeDown"] = function (){  
		
		//var setColorCreator = new dialog.basicCreator();
		var certainAction = function(r,g,b,alpha){
			defultValue.red = r;
			defultValue.green = g;
			defultValue.blue = b;
			defultValue.alpha = alpha;
			colorExample.changeBgColor([r,g,b,alpha]);
			}
		dialog.setColor.show([defultValue.red,
							  defultValue.green,
							  defultValue.blue,
							  defultValue.alpha],
							 certainAction);
		
		var top = dialog.findTheTopParent(colorExample);
		dialog.setColor.addActiveNowBy(top);
		}
	
	var colorExample = new dialog.frame("colorExample",[],[],colorExampleBgColor,colorExampleBgColorActivtion);
	return colorExample;
	}



//比较颜色色块
dialog.colorComparison = function(){
	var colorBgColor = new Array;
	colorBgColor[0] = [defultValue.red,defultValue.green,defultValue.blue,defultValue.alpha];
	colorBgColor[1] = 75;
	colorBgColor[2] = 35;
	
	var colorFrame = new dialog.frame("comparisonColor",[],[],colorBgColor,[]);
	
	var thisTexture = new Array;
		thisTexture[0] = textures["comparisonBg"];
	
	thisFrame = new dialog.frame("colorComparison",[],thisTexture,[],[]);
	thisFrame.addFrame([colorFrame,0,0]);
	return thisFrame;
	}

//创建全局颜色库
dialog.createColorGlobal = function(){
	var thisBgColor = new Array;
	thisBgColor[1] = 75;
	thisBgColor[2] = 75;
	
	var thisFrame = new dialog.frame("colorGlobal",[],[],thisBgColor,[]);
	var colorExample = dialog.createColorExample();
	
	thisFrame.addFrame([colorExample,0,0]);
	return thisFrame
	}

//创建一个颜色库中的颜色色块。
dialog.createColorBlock = function(){
	var thisBgColor = new Array;
	thisBgColor[0] = [defultValue.red,defultValue.green,defultValue.blue,defultValue.alpha];
	thisBgColor[1] = 24;
	thisBgColor[2] = 24;
	
	var thisActivtion = new Array;
	
	thisActivtion["activeDown"] = function (){ 
	
	
	customizeCursor.activeChildByName("brushColor",["changeBgColor",[this.bgColor[0],
																		this.bgColor[1],
																		this.bgColor[2],
																		1]])
	
	
	//加入该色块属于自定义，则被点中是需要弹出两个按钮
	if(this.parent.parent.name == "colorCustomizeFrame"){
		
		//更改按钮
			var changeTexture = new Array;
				changeTexture[0] =  textures["changeButton"];
			var changeActive = new Array;
				changeActive["activeDown"] = function(){
					this.changeBgImageTexture([textures["changeButton"]]);
					
					var certainAction = function(r,g,b,alpha){
						colorSelect.changeBgColor([r,g,b,alpha]);
						var findFrames = totalColorUnitFrame.findFrameByName(["colorCustomizeFrame"]);
						var theLibrary = findFrames[0].findFrameByName(["colorLibrary"]);
							for(var n=0;n < theLibrary[0].child.length;n++){
								colorCustomize[n][0] = theLibrary[0].child[n].bgColor[0];
								colorCustomize[n][1] = theLibrary[0].child[n].bgColor[1];
								colorCustomize[n][2] = theLibrary[0].child[n].bgColor[2];
								colorCustomize[n][3] = theLibrary[0].child[n].bgColor[3];
								}
						}
					
					dialog.setColor.show(colorSelect.bgColor,certainAction);
					var top = dialog.findTheTopParent(colorSelect);
					dialog.setColor.addActiveNowBy(top);
					}
				changeActive["activeOver"] = function(){
					this.changeBgImageTexture([textures["changeButtonOn"]]);
				}
				changeActive["activeLeave"] = function(){
					this.changeBgImageTexture([textures["changeButton"]]);
				}
		
		var changeButton = new dialog.frame("changeButton",[],changeTexture,[],changeActive);
		
			//删除按钮
			var deleteTexture = new Array;
				deleteTexture[0] =  textures["deleteButton"];
			var deleteActive = new Array;
				deleteActive["activeDown"] = function(){
					this.changeBgImageTexture([textures["deleteButtonOn"]]);
				
					//if((confirm("是否删除该颜色"))){
					
					totalColorUnitFrame.subFrameByName(["colorMarkSign"]);
					var thisColorLibrary = this.parent.findFrameByName(["colorLibrary"]);
					for(var colorN = 0;colorN < thisColorLibrary[0].child.length;colorN++){
						if(thisColorLibrary[0].child[colorN] == colorSelect ){
							thisColorLibrary[0].subFrameByName(["colorBlock"]);
							colorCustomize.splice(colorN,1);
							
							if(colorCustomize.length == 0){
								totalColorUnitFrame.subFrameByName(["emptyButton"]);
								totalColorUnitFrame.subFrameByName(["joinButton"]);
								totalColorUnitFrame.subFrameByName(["changeButton"]);
								totalColorUnitFrame.subFrameByName(["deleteButton"]);
								}
							var ii = 0;
							for(var n = 0;n < colorCustomize.length ;n++){
								var aNewColorUnit = dialog.createColorBlock();
								aNewColorUnit.changeBgColor([colorCustomize[n][0],
																colorCustomize[n][1],
																colorCustomize[n][2],
																colorCustomize[n][3]
																 ]);		
						
								if(n%3 == 0){ii = n/3}
								thisColorLibrary[0].addFrame([aNewColorUnit,n%3*25+1,ii*25+1]);
								}
							}
						//}
						}
						
										
										
						
					}
				deleteActive["activeOver"] = function(){
					this.changeBgImageTexture([textures["deleteButtonOn"]]);
					
					
					
					
					
					
				}
				deleteActive["activeLeave"] = function(){
					this.changeBgImageTexture([textures["deleteButton"]]);
				}
		
		var deleteButton = new dialog.frame("deleteButton",[],deleteTexture,[],deleteActive);
		
		this.parent.parent.addFrame([changeButton,79,23]);//应该让他消隐出来
		this.parent.parent.addFrame([deleteButton,79,48]);
		}else{
			totalColorUnitFrame.subFrameByName(["changeButton"]);
			totalColorUnitFrame.subFrameByName(["deleteButton"]);
			}
	
	//色块的标记
		var colorMarkSelect = new Array;
		colorMarkSelect = totalColorUnitFrame.findFrameByName(["colorMarkSign"]);
		if(colorMarkSelect[0]){
			colorMarkSelect[0].moveTo([this.parent.parent.x+this.parent.x+this.x,this.parent.parent.y+this.parent.y+this.y]);
			}else{
				totalColorUnitFrame.subFrameByName(["colorMarkSign"]);
				colorMarkSelect[0]= new dialog.frame("colorMarkSign",[],[textures["colorMark"]],[],[]);
				totalColorUnitFrame.addFrame([colorMarkSelect[0],this.parent.parent.x+this.parent.x+this.x,this.parent.parent.y+this.parent.y+this.y]);
				colorMarkSelect[0].changeZ([8]);
				}
				
		defultValue.red = this.bgColor[0];
		defultValue.green = this.bgColor[1];
		defultValue.blue = this.bgColor[2];
		defultValue.alpha = this.bgColor[3];
		
		this.changeScale([0.97]); //缩放的中心要改成物体的中心
		
		colorSelect = this;
		
		for (var n = 0;n < frameActiveNow.length ;n++){
			for (var nSub = 0;nSub < frameActiveNow[n].length ;nSub++){
				frameActiveNow[n][nSub].activeChildByName("colorExample",["changeBgColor",[defultValue.red,
																					defultValue.green,
																					defultValue.blue,
																					defultValue.alpha
																						]]);
				}
			}
		}
	thisActivtion["activeOver"] = function (){ 
			this.changeScale([1]);
			var thisTop = dialog.findTheTopParent(this);
			
			thisTop.subFrameByName(["colorComparison"]);
			
			var colorComparison = dialog.colorComparison();
			colorComparison.child[0].changeBgColor([this.bgColor[0],
										   this.bgColor[1],
										   this.bgColor[2],
										   this.bgColor[3]]);
			
			thisTop.activeChildByName("colorGlobal",["addFrame",[colorComparison,0,40]]);
			}

	var colorBlock = new dialog.frame("colorBlock",[],[],thisBgColor,thisActivtion);
	return colorBlock;
	}

//创建用按照某数组排列的颜色库,最大的展示个数
dialog.createColorLibrary = function(colorArray,maxNo){
	var thisBgColor = new Array;
	thisBgColor[1] = 75;
	thisBgColor[2] = 125;
	
	var thisFrame = new dialog.frame("colorLibrary",[],[],thisBgColor,[]); 
	 
	if(colorArray){
	var ii = 0;
		for(var n = 0;n < colorArray.length;n++){
			var aNewColorUnit = dialog.createColorBlock();
			aNewColorUnit.changeBgColor([colorArray[n][0],
											colorArray[n][1],
											colorArray[n][2],
											colorArray[n][3]
											 ]);		
	
			if(n%3 == 0){ii = n/3;}
			thisFrame.addFrame([aNewColorUnit,n%3*25+1,ii*25+1]);
			}
		for(var nn=colorArray.length;nn < maxNo;nn++){
			var aNewColorUnit = dialog.createColorBlock();
			aNewColorUnit.changeBgColor([0,0,0,0]);
			if(nn%3 == 0){ ii = nn/3;}
			thisFrame.addFrame([aNewColorUnit,nn%3*25+1,ii*25+1]);
			aNewColorUnit.loseActive();
			}
		}else{
			var ii = 0;
			for(var n=0;n < maxNo;n++){
				var aNewColorUnit = dialog.createColorBlock();
				aNewColorUnit.changeBgColor([0,0,0,0]);
				if(n%3 == 0){ ii = n/3;}
				thisFrame.addFrame([aNewColorUnit,n%3*25+1,ii*25+1]);
				aNewColorUnit.loseActive();
				}
			}
	return thisFrame;
	}

//创建常用颜色的颜色库
dialog.createColorOftenFrame = function(){
	
	var thisBgColor = new Array;
	thisBgColor[1] = 75;
	thisBgColor[2] = 75;
	
	var thisFrame = new dialog.frame("colorOften",[],[],thisBgColor,[]);
	 
	var ii = 0;
	for(var n=0;n < colorOftenUse.length && n < 9;n++){
		
		var aNewColorOftenUnit = dialog.createColorBlock();
		
		aNewColorOftenUnit.changeBgColor([colorOftenUse[n][0][0]/255,
										  colorOftenUse[n][0][1]/255,
										  colorOftenUse[n][0][2]/255,
										  colorOftenUse[n][0][3]/255
															]);
		if(n%3 == 0){ii = n/3}
		thisFrame.addFrame([aNewColorOftenUnit,n%3*25+1,ii*25+1]);
		}
	return thisFrame;
	}	

//每一项的标题
dialog.createColorUnitTitle = function(contentText){
	var thisText = new Array;
	thisText[0] = contentText;
	thisText[1] = "left";
	thisText[2] = "middle";
	thisText[4] = 10;
	
	var thisBgColor = new Array;
	thisBgColor[1] = 80;
	thisBgColor[2] = 20;
	
	var thisTitle = new dialog.frame("thisTitle",thisText,[],thisBgColor,[]);
	return thisTitle;
	}


//创建自定义的清空按钮
dialog.createEmptyButtonCustomize = function(){
	var emptyTexture = new Array;
		emptyTexture[0] =  textures["emptyButton"];
	var emptyActive = new Array;
		emptyActive["activeDown"] = function(){
			this.changeBgImageTexture([textures["emptyButton"]]);
			
			colorCustomize = [];
			var findFrames = totalColorUnitFrame.findFrameByName(["colorCustomizeFrame"]);
			findFrames[0].subFrameByName(["colorBlock"]);
			totalColorUnitFrame.subFrameByName(["emptyButton"]);
			totalColorUnitFrame.subFrameByName(["joinButton"]);
			totalColorUnitFrame.subFrameByName(["changeButton"]);
			totalColorUnitFrame.subFrameByName(["deleteButton"]);
			totalColorUnitFrame.subFrameByName(["colorMarkSign"]);
			}
		emptyActive["activeOver"] = function(){
			this.changeBgImageTexture([textures["emptyButtonOn"]]);
			
			if(!mouseCursorStatus){
				mouseAmong = 2;
				mouseCursorStatus = mouseCursor;
				mouseCursor = "DEFAULT";
				}
			if(this.child[0]){
				this.child[0].changeFrameAlpha([1]);
				}else{
					//按钮的文字提示-------------------------------------------------------------------------------------
						var buttonTipsBlackBg =  new dialog.frame("buttonTipsBlackBg",[],[],[[0,0,0,1],80,18],[]);
						var buttonTips =  new dialog.frame("buttonTips",["清空配色方案","center","middle"],[],[[0.9,0.9,0.9,1],78,16],[]);
						
						buttonTipsBlackBg.addFrame([buttonTips,1,1]);
						this.addFrame([buttonTipsBlackBg,20,20]);
						buttonTipsBlackBg.changeZ([8]);
					}		
			
		}
		emptyActive["activeLeave"] = function(){
			if(mouseCursorStatus && mouseAmong == 2){
				mouseCursor = mouseCursorStatus;
				mouseCursorStatus=null;
				}

			this.changeBgImageTexture([textures["emptyButton"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([0]);
			}
		}
			
	var emptyButton = new dialog.frame("emptyButton",[],emptyTexture,[],emptyActive);
	return emptyButton;
	}



//创建自定义的加入按钮
dialog.createJoinButtonCustomize = function(){
	var joinTexture = new Array;
		joinTexture[0] =  textures["joinButton"];
	var joinActive = new Array;
		joinActive["activeDown"] = function(){
			this.changeBgImageTexture([textures["joinButton"]]);
			if(colorCustomize.length != 0){
				var colorConversion = new Array;
				for(var ii =0;ii < colorCustomize.length;ii++){
					colorConversion[ii] =  new Array;
					
					colorConversion[ii][0] = colorCustomize[ii][0];
					colorConversion[ii][1] = colorCustomize[ii][1];
					colorConversion[ii][2] = colorCustomize[ii][2];
					colorConversion[ii][3] = colorCustomize[ii][3];
					
					}
				colorLibraryArray.push(colorConversion);
					
				}
			}
		joinActive["activeOver"] = function(){
			
			if(!mouseCursorStatus){
				mouseAmong = 3;
				mouseCursorStatus = mouseCursor;
				mouseCursor = "DEFAULT";
				}
			
			this.changeBgImageTexture([textures["joinButtonOn"]]);
			
			if(this.child[0]){
				this.child[0].changeFrameAlpha([1]);
				}else{
					//按钮的文字提示-------------------------------------------------------------------------------------
						var buttonTipsBlackBg =  new dialog.frame("buttonTipsBlackBg",[],[],[[0,0,0,1],80,18],[]);
						var buttonTips =  new dialog.frame("buttonTips",["加入配色方案","center","middle"],[],[[0.9,0.9,0.9,1],78,16],[]);
						
						buttonTipsBlackBg.addFrame([buttonTips,1,1]);
						this.addFrame([buttonTipsBlackBg,20,20]);
						buttonTipsBlackBg.changeZ([8]);
					}		
		}
		joinActive["activeLeave"] = function(){
			if( mouseCursorStatus && mouseAmong==3){
				mouseCursor = mouseCursorStatus;
				mouseCursorStatus = null;
				}
			
			this.changeBgImageTexture([textures["joinButton"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([0]);
				}
		}
	var joinButton = new dialog.frame("joinButton",[],joinTexture,[],joinActive);
	return 	joinButton;
		}



////////////////////////////////////创建总的颜色单元///////////////////////////////////
dialog.createTotalColorUnit = function(){
	
	var thisTexture = new Array;
		thisTexture[0] = textures["colorLibrary"];
	
	totalColorUnitFrame = new dialog.frame("totalColorUnitFrame",[],thisTexture,[],[]);
	
	totalColorUnitFrame.activeOver = function(){
		this.subFrameByName(["colorComparison"]);
		}
	totalColorUnitFrame.activeLeave = function(){
		this.subFrameByName(["colorComparison"]);
		}


//---------------------系统颜色库---------------------------------------------------------------------------------------------
	var colorLibraryFrameBody = dialog.createColorLibrary(colorLibraryArray[colorLibraryArrayNo],15);
	
	
	var colorLibraryBgColor = new Array;
	colorLibraryBgColor[1] = 105;
	colorLibraryBgColor[2] = 150;
	
	var colorLibraryFrame = new dialog.frame("colorLibraryFrame",[],[],colorLibraryBgColor,[]);
	
	colorLibraryFrame.addFrame([colorLibraryFrameBody,2,22]);
	
	if(colorLibraryArray.length > 1){
		//切换颜色库按钮
		var switchTexture = new Array;
			switchTexture[0] =  textures["switchButton"];
		var switchActive = new Array;
			switchActive["activeDown"] = function(){
				this.changeBgImageTexture([textures["switchButton"]]);
				dialog.chooseColor(colorLibraryStart);
				}
			switchActive["activeOver"] = function(){
				this.changeBgImageTexture([textures["switchButtonOn"]]);
				if(!mouseCursorStatus){
					mouseAmong =4;
					mouseCursorStatus = mouseCursor;
					mouseCursor = "DEFAULT";
					}
				
			if(this.child[0]){
				this.child[0].changeFrameAlpha([1]);
				}else{
					//按钮的文字提示-------------------------------------------------------------------------------------
						var buttonTipsBlackBg =  new dialog.frame("buttonTipsBlackBg",[],[],[[0,0,0,1],80,18],[]);
						var buttonTips =  new dialog.frame("buttonTips",["更改颜色方案","center","middle"],[],[[0.9,0.9,0.9,1],78,16],[]);
						
						buttonTipsBlackBg.addFrame([buttonTips,1,1]);
						this.addFrame([buttonTipsBlackBg,20,20]);
						buttonTipsBlackBg.changeZ([8]);
					}		
				
				}
			switchActive["activeLeave"] = function(){
				
				if(mouseCursorStatus  && mouseAmong == 4 ){
					mouseCursor =mouseCursorStatus;
					mouseCursorStatus= null;
					}
				
				this.changeBgImageTexture([textures["switchButton"]]);
				if(this.child[0]){
					this.child[0].changeFrameAlpha([0]);
					}
				}
		var switchButton = 	 new dialog.frame("switchButton",[],switchTexture,[],switchActive);
		
		colorLibraryFrame.addFrame([switchButton,79,23]);
		}			
	
	
//---------------------------自定义颜色库-----------------------------------------------------------------------
	var colorCustomizeBody = dialog.createColorLibrary(colorCustomize,15);

	
	var colorCustomizeBgColor = new Array;
	colorCustomizeBgColor[1] = 105;
	colorCustomizeBgColor[2] = 150;
	
	var colorCustomizeFrame = new dialog.frame("colorCustomizeFrame",[],[],colorCustomizeBgColor,[]);
	
	colorCustomizeFrame.addFrame([colorCustomizeBody,2,22]);
	
	if(colorCustomize.length != 0){
			//清空按钮
		var emptyButton = dialog.createEmptyButtonCustomize();
			
			//加入按钮
		var joinButton = dialog.createJoinButtonCustomize();
		
	colorCustomizeFrame.addFrame([emptyButton,79,73]);
	colorCustomizeFrame.addFrame([joinButton,79,98]);
		}
	
//-----------------------常用颜色库------------------------------------------------------------------------
	
	var colorOftenFrameBody = dialog.createColorOftenFrame();
	
	var colorOftenBgColor = new Array;
	colorOftenBgColor[1] = 105;
	colorOftenBgColor[2] = 100;
	
	var colorOftenFrame = new dialog.frame("colorOftenFrame",[],[],colorOftenBgColor,[]);
	
	colorOftenFrame.addFrame([colorOftenFrameBody,2,22]);
//--------------------------当前颜色----------------------------------------------------------------------
	var colorExampleBody = dialog.createColorGlobal();
	
	//添加到自定义的按钮
	var customizeTexture = new Array;
		customizeTexture[0] =  textures["customizeButton"];
	var customizeActive = new Array;
		customizeActive["activeDown"] = function(){
			
		//如果自定义中没有清空和加入按钮
		var thisFindFrames = totalColorUnitFrame.findFrameByName(["colorCustomizeFrame"]);
		var haveButton = false; //默认没有该开关
		for(var c =0;c < thisFindFrames[0].child.length;c++){
			if(thisFindFrames[0].child[c].name == "emptyButton"){
				haveButton = true; 
				}
			}
		if(!haveButton){
		var emptyButton = dialog.createEmptyButtonCustomize();
			
			//加入按钮
		var joinButton = dialog.createJoinButtonCustomize();
		thisFindFrames[0].addFrame([emptyButton,79,73]);
		thisFindFrames[0].addFrame([joinButton,79,98]);
			}
		
		this.changeBgImageTexture([textures["customizeButton"]]);
			
		colorPreload = [defultValue.red,
						defultValue.green,
						defultValue.blue,
						defultValue.alpha];
		
		var ifHave = false; //是否已有这个颜色的开关。默认为没有这个颜色
		for(var n=0;n < colorCustomize.length;n++){
			if(colorPreload.toString() == colorCustomize[n].toString()){
				ifHave = true;
				dialog.tips.showBy("自定义中已经存在此颜色",500);
				}
			}
		if(!ifHave){
			if(colorCustomize.length < 15){
				colorCustomize.push(colorPreload);
				
				//重新加载自定义
				var findFrames = totalColorUnitFrame.findFrameByName(["colorCustomizeFrame"]);
				var theLibrary = findFrames[0].findFrameByName(["colorLibrary"]);
				var colorBlock = dialog.createColorBlock();
				var ii = (colorCustomize.length-1 - (colorCustomize.length-1)%3)/3;
				theLibrary[0].addFrame([colorBlock,(colorCustomize.length-1)%3*25+1,ii*25+1]);
				for(var k=0;k < colorCustomize.length;k++){
					theLibrary[0].child[k].changeBgColor([colorCustomize[k][0],
														  colorCustomize[k][1],
														  colorCustomize[k][2],
														  colorCustomize[k][3]]);
										}
					}else{
						dialog.tips.showBy("自定义颜色数目不能超过15个",500);
						}
				}
			}
			
		customizeActive["activeOver"] = function(){
			this.changeBgImageTexture([textures["customizeButtonOn"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([1]);
				}else{
					//按钮的文字提示-------------------------------------------------------------------------------------
						var buttonTipsBlackBg =  new dialog.frame("buttonTipsBlackBg",[],[],[[0,0,0,1],80,18],[]);
						var buttonTips =  new dialog.frame("buttonTips",["加入我的颜色","center","middle"],[],[[0.9,0.9,0.9,1],78,16],[]);
						
						buttonTipsBlackBg.addFrame([buttonTips,1,1]);
						this.addFrame([buttonTipsBlackBg,20,20]);
						buttonTipsBlackBg.changeZ([8]);
					}		
		}
		customizeActive["activeLeave"] = function(){
			this.changeBgImageTexture([textures["customizeButton"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([0]);
				}
		}
 
 var customizeButton = new dialog.frame("customizeButton",[],customizeTexture,[],customizeActive);
	
	//拾取颜色的按钮
	var dropperTexture = new Array;   
		dropperTexture[0] =  textures["dropperButton"];
	var dropperActive = new Array;
		dropperActive["activeDown"] = function(){
			this.changeBgImageTexture([textures["dropperButtonOn"]]);
			}
		dropperActive["activeOver"] = function(){
			this.changeBgImageTexture([textures["dropperButtonOn"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([1]);
				}else{
					//按钮的文字提示-------------------------------------------------------------------------------------
						var buttonTipsBlackBg =  new dialog.frame("buttonTipsBlackBg",[],[],[[0,0,0,1],80,18],[]);
						var buttonTips =  new dialog.frame("buttonTips",["拾取颜色","center","middle"],[],[[0.9,0.9,0.9,1],78,16],[]);
						
						buttonTipsBlackBg.addFrame([buttonTips,1,1]);
						this.addFrame([buttonTipsBlackBg,20,20]);
						buttonTipsBlackBg.changeZ([8]);
					}		
		}
		dropperActive["activeLeave"] = function(){
			this.changeBgImageTexture([textures["dropperButton"]]);
			if(this.child[0]){
				this.child[0].changeFrameAlpha([0]);
				}
			
		}

var dropperButton = new dialog.frame("dropperButton",[],dropperTexture,[],dropperActive);

//---------------------
	var colorExampleBgColor = new Array;
		colorExampleBgColor[1] = 105;
		colorExampleBgColor[2] = 100;
	
	var colorExampleFrame = new dialog.frame("colorExampleFrame",[],[],colorExampleBgColor,[]);
	
	colorExampleFrame.addFrame([colorExampleBody,2,22]);
	colorExampleFrame.addFrame([customizeButton,79,23]);
	colorExampleFrame.addFrame([dropperButton,79,48]);
	
	
//外观主题-------------------------------------------------------------------------------------------------
	var themeTexture = new Array;
		themeTexture[0] = textures["colorTBg"];

	var colorTheme = new dialog.frame("colorTheme",[],themeTexture,[],[]);
	
	var textLibrary =  dialog.createColorUnitTitle("配色方案");
	var textCustomize = dialog.createColorUnitTitle("我的颜色");
	var textOften = dialog.createColorUnitTitle("常用颜色");
	var textNow = dialog.createColorUnitTitle("当前色彩");
	
	colorTheme.addFrame([textLibrary,2,10]);
	colorTheme.addFrame([textCustomize,2,160]);
	colorTheme.addFrame([textOften,2,310]);
	colorTheme.addFrame([textNow,2,410]);
	
//------------------------------------------------------------
	
	totalColorUnitFrame.addFrame([colorLibraryFrame,0,5]);
	totalColorUnitFrame.addFrame([colorCustomizeFrame,0,155]);
	totalColorUnitFrame.addFrame([colorOftenFrame,0,305]);
	totalColorUnitFrame.addFrame([colorExampleFrame,0,405]);
	totalColorUnitFrame.addFrame([colorTheme,0,0]);

	colorTheme.changeZ([10]);

	totalColorUnitFrame.moveTo([-totalColorUnitFrame.width,0]);
	dialog.moveDialogTo(totalColorUnitFrame,0,0);
	dialog.tips.showBy("画笔涂抹模式已经打开，先在左边点中想要使用的色彩，然后到场景中的方块上点击就可以上色了。可以单击上色；或者点中后按住左键不放，利用拖动给多个方块上色。  PS：点中空白的地方会退回编辑模式，所以...你可要看准了!",800);
	totalColorUnitFrame.addNewActiveNow();
	}

////////////////////////////////////////////////////////////////////////////////////


//选择预览颜色库的色块
dialog.chooseColorBlock = function(){
	var thisBgColor = new Array;
	thisBgColor[0] = [1,1,1,1];
	thisBgColor[1] = 20;
	thisBgColor[2] = 20;
	
	var thisFrame = new dialog.frame("chooseColorBlock",[],[],thisBgColor,[]);
	return thisFrame;
	}

//选择预览颜色库的一条
dialog.chooseColorUnit = function(No){
	var thisBgColor = new Array;
	thisBgColor[1] = 68;
	thisBgColor[2] = 108;
	
	var thisActivtion = new Array;
	thisActivtion["activeDown"] = function (){ 
  	colorLibraryArrayNo = No;//让颜色库记住当前选中第几套配色方案
	
//-------------------------------------------删除整个预览选择颜色库----不删的话就得实时更新--------------------------
	chooseColorFrame.transform.parent = null;
	chooseColorFrame.delActiveNow();
	dialog.removeDialog(chooseColorFrame);
		
//-------------------------------------------替换颜色库---------只重新排列颜色--------------------------
		var findFrames = totalColorUnitFrame.findFrameByName(["colorLibraryFrame"]);
		var theLibrary = findFrames[0].findFrameByName(["colorLibrary"]);
		var copyLibrary0 = this.findFrameByName(["longColorItem0"]);
		var copyLibraryColors0 = copyLibrary0[0].findFrameByName(["chooseColorBlock"]);
		
		var copyLibrary1 = this.findFrameByName(["longColorItem1"]);
		var copyLibraryColors1 = copyLibrary1[0].findFrameByName(["chooseColorBlock"]);
		
		var copyLibrary2 = this.findFrameByName(["longColorItem2"]);
		var copyLibraryColors2 = copyLibrary2[0].findFrameByName(["chooseColorBlock"]);
		
			for(var k=0;k < 15;k++){
					if(k%3==0 && k/3 < copyLibraryColors0.length){
						theLibrary[0].child[k].getActive();
						theLibrary[0].child[k].changeBgColor([copyLibraryColors0[k/3].bgColor[0],
															   copyLibraryColors0[k/3].bgColor[1],
															   copyLibraryColors0[k/3].bgColor[2],
															   copyLibraryColors0[k/3].bgColor[3]
															  ]);
						}else if(k%3==1 && (k-1)/3 < copyLibraryColors1.length){
						theLibrary[0].child[k].getActive();
						theLibrary[0].child[k].changeBgColor([copyLibraryColors1[(k-1)/3].bgColor[0],
															   copyLibraryColors1[(k-1)/3].bgColor[1],
															   copyLibraryColors1[(k-1)/3].bgColor[2],
															   copyLibraryColors1[(k-1)/3].bgColor[3]
															  ]);
							}else if(k%3==2 && (k-2)/3 < copyLibraryColors2.length){
							theLibrary[0].child[k].getActive();
							theLibrary[0].child[k].changeBgColor([copyLibraryColors2[(k-2)/3].bgColor[0],
																   copyLibraryColors2[(k-2)/3].bgColor[1],
																   copyLibraryColors2[(k-2)/3].bgColor[2],
																   copyLibraryColors2[(k-2)/3].bgColor[3]
																  ]);
								}else{
									theLibrary[0].child[k].changeBgColor([0,0,0,0]);
									theLibrary[0].child[k].loseActive();
									}
					}
			}
	thisActivtion["activeOver"] = function(){ 
		var markSelect = new Array;
		markSelect = chooseColorFrame.findFrameByName(["markSign"]);
		if(markSelect[0]){
			markSelect[0].moveTo([this.x,this.y-11]);
			var compColorNo = chooseColorFrame.findFrameByName(["chooseColorUnit"]);
			for(var thisNo=0;thisNo < compColorNo.length;thisNo++){
				if(this == compColorNo[thisNo]){
					markSelect[0].markNo = thisNo;
					}
				}
			}else{
				markSelect[0]= new dialog.frame("markSign",[],[textures["librarySelect_cursor"]],[],[]);
				chooseColorFrame.addFrame([markSelect[0],this.x,this.y-11]);
				markSelect[0].changeZ([8]);
				var compColorNo = chooseColorFrame.findFrameByName(["chooseColorUnit"]);
				for(var thisNo=0;thisNo < compColorNo.length;thisNo++){
					if(this == compColorNo[thisNo]){
						markSelect[0].markNo = thisNo;
						}
					}
				
				//预览选择颜色框的删除当前颜色框按钮
				var colorDeleteActive = new Array;
				colorDeleteActive["activeDown"] = function(){
					
					//if((confirm("你确定要删除该配色方案吗？"))){
						if(colorLibraryArray.length>7){
							if(colorLibraryStart+7 == colorLibraryArray.length){
								colorLibraryStart--;
								var thisTop = dialog.findTheTopParent(this);
								var chooseColors =  thisTop.findFrameByName(["chooseColorUnit"]);
								dialog.moveDialogByDirection(chooseColors.slice(0,this.parent.markNo),73,0,10,0);
								
								chooseColors[this.parent.markNo].moveTo([-500,-500]);
								var thisTopChildLength = thisTop.child.length; 
								for(var thisN = 0;thisN < thisTopChildLength;thisN++){
									if(thisTop.child[thisN] == chooseColors[this.parent.markNo]){
										thisTop.child.splice(thisN,1);
										}
									}
								chooseColorFrame.subFrameByName(["markSign"]);
								}else{
									var thisTop = dialog.findTheTopParent(this);
									var chooseColors =  thisTop.findFrameByName(["chooseColorUnit"]);
									dialog.moveDialogByDirection(chooseColors.slice(this.parent.markNo+1,chooseColors.length),-73,0,10,this.parent.markNo);
									chooseColors[this.parent.markNo].moveTo([-500,-500]);
									
									var thisTopChildLength = thisTop.child.length; 
									for(var thisN = 0;thisN < thisTopChildLength;thisN++){
										if(thisTop.child[thisN] == chooseColors[this.parent.markNo]){
											thisTop.child.splice(thisN,1);
											}
										}
									
									chooseColorFrame.subFrameByName(["markSign"]);
									}
					}else{
						
						var thisTop = dialog.findTheTopParent(this);
						var chooseColors =  thisTop.findFrameByName(["chooseColorUnit"]);
						if(this.parent.markNo != chooseColors.length-1){
							dialog.moveDialogByDirection(chooseColors.slice(this.parent.markNo+1,chooseColors.length),-73,0,10,this.parent.markNo);
							}
						
						chooseColors[this.parent.markNo].moveTo([-500,-500]);
							
						var thisTopChildLength = thisTop.child.length; 
						
						for(var thisN = 0;thisN < thisTopChildLength;thisN++){
							if(thisTop.child[thisN] == chooseColors[this.parent.markNo]){
								thisTop.child.splice(thisN,1);
								}
							}
						chooseColorFrame.subFrameByName(["markSign"]);
						}
					
					colorLibraryArray.splice(this.parent.markNo,1);
					if(colorLibraryArray.length == 0){ 
						chooseColorFrame.transform.parent = null;
						chooseColorFrame.delActiveNow();
						dialog.removeDialog(chooseColorFrame);
						
						totalColorUnitFrame.subFrameByName(["switchButton"]);
						colorLibraryArrayNo = 0;
					}
					//}
				}
				
				colorDeleteActive["activeOver"] = function(){
				this.changeBgImageTexture([textures["librarySelect_del_red"]]);
				}
				
				colorDeleteActive["activeLeave"] = function(){
				this.changeBgImageTexture([textures["librarySelect_del_white"]]);
				}
				
				var colorDeleteButton = new dialog.frame("colorDeleteButton",[],[textures["librarySelect_del_white"]],[],colorDeleteActive);
				markSelect[0].addFrame([colorDeleteButton,0,0]);
				}
	}
	thisActivtion["activeLeave"] = function (){ 
	}
	
	var thisFrame = new dialog.frame("chooseColorUnit",[],[],thisBgColor,thisActivtion);
	
	
	//添加三个小的颜色条
	var longColorItem = new Array;
	
	var colorItemTexture = new Array;
		colorItemTexture[0] = textures["librarySelect_colorBg"];
	
	var colorItemActive = new Array;
	
	 longColorItem[0] = new dialog.frame("longColorItem0",[],colorItemTexture,[],[]);
	 longColorItem[1] = new dialog.frame("longColorItem1",[],colorItemTexture,[],[]);	
	 longColorItem[2] = new dialog.frame("longColorItem2",[],colorItemTexture,[],[]);		
	
	var ii = 0;
	for(var n=0;n < colorLibraryArray[No].length;n++){
		var colorBlock = dialog.chooseColorBlock();
		
		colorBlock.changeBgColor([colorLibraryArray[No][n][0],
								   colorLibraryArray[No][n][1],
								   colorLibraryArray[No][n][2],
								   colorLibraryArray[No][n][3]]);
		if(n%3 == 0){ii = n/3}
		longColorItem[n%3].addFrame([colorBlock,1,ii*21]);
		}
	
	var longColorItemCover = new Array;
	longColorItemCover[0] = new dialog.frame("longColorItemCover",[],[textures["librarySelect_colorFrame"]],[],[]);
	longColorItemCover[1] = new dialog.frame("longColorItemCover",[],[textures["librarySelect_colorFrame"]],[],[]);
	longColorItemCover[2] = new dialog.frame("longColorItemCover",[],[textures["librarySelect_colorFrame"]],[],[]);
	
	longColorItem[0].addFrame([longColorItemCover[0],0,0])	;
	longColorItem[1].addFrame([longColorItemCover[1],0,0])	;
	longColorItem[2].addFrame([longColorItemCover[2],0,0])	;
	
	thisFrame.addFrame([longColorItem[0],2,0])	;
	thisFrame.addFrame([longColorItem[1],23,0]);
	thisFrame.addFrame([longColorItem[2],44,0]);

	return thisFrame;
	}

/////////////////////////////////////////“预览选择颜色库”//////////////////////////////////////////////////
dialog.chooseColor = function(startNo){
	var thisTexture = new Array;
	thisTexture[0] =  textures["librarySelect_bg"];
	
	chooseColorFrame = new dialog.frame("chooseColor",[],thisTexture,[],[]);
	
	for( var n =0;n < colorLibraryArray.length ;n++){
		var thisColorUnit = dialog.chooseColorUnit(n);
		chooseColorFrame.addFrame([thisColorUnit,(n-startNo)*73+104,24]);
		if(n>=startNo && n < startNo +7){
			thisColorUnit.getActive();
			thisColorUnit.activeChildByName("longColorItem0",["changeFrameAlpha",[1]]);
			thisColorUnit.activeChildByName("longColorItem1",["changeFrameAlpha",[1]]);
			thisColorUnit.activeChildByName("longColorItem2",["changeFrameAlpha",[1]]);
			}else{
				thisColorUnit.loseActive();
				thisColorUnit.activeChildByName("longColorItem0",["changeFrameAlpha",[0]]);
				thisColorUnit.activeChildByName("longColorItem1",["changeFrameAlpha",[0]]);
				thisColorUnit.activeChildByName("longColorItem2",["changeFrameAlpha",[0]]);
				}
		}
	
	var forwordButton =  new dialog.frame("forwordButton",[],[textures["librarySelect_left_gray"]],[],[]);
	var backwordButton = new dialog.frame("backwordButton",[],[textures["librarySelect_right_gray"]],[],[]);
	
	var maskLeft = new dialog.frame("maskLeft",[],[textures["librarySelect_leftCover"]],[],[]);
		maskLeft.addFrame([forwordButton,1,57]);
		maskLeft.activeDown = function(){
			if(!colorFrameMoveTime){
				if(colorLibraryStart == 0){dialog.tips.showBy("到头了",200);}
				if(colorLibraryStart > 0){
				colorLibraryStart--;
				var thisTop = dialog.findTheTopParent(this);
				var chooseColors =  thisTop.findFrameByName(["chooseColorUnit"]);
					dialog.moveDialogByDirection(chooseColors,73,0,10,0);
				}
			}
			forwordButton.changeBgImageTexture([textures["librarySelect_left_gray"]]);
			}
		maskLeft.activeOver = function(){
			chooseColorFrame.subFrameByName(["markSign"]);
			
			forwordButton.changeBgImageTexture([textures["librarySelect_left_blue"]]);
			}
			
		maskLeft.activeLeave = function(){
			forwordButton.changeBgImageTexture([textures["librarySelect_left_gray"]]);
			}
			
	
	var maskRight = new dialog.frame("maskRight",[],[textures["librarySelect_rightCover"]],[],[]);
		maskRight.addFrame([backwordButton,4,57]);
		maskRight.activeDown = function(){
			if(!colorFrameMoveTime){
				if(colorLibraryStart == colorLibraryArray.length -7){dialog.tips.showBy("到尾了",200);}
				if(colorLibraryStart < colorLibraryArray.length -7){
				colorLibraryStart++;
				var thisTop = dialog.findTheTopParent(this);
				var chooseColors =  thisTop.findFrameByName(["chooseColorUnit"]);
					dialog.moveDialogByDirection(chooseColors,-73,0,10,0);//整体移动
					}
				}
			backwordButton.changeBgImageTexture([textures["librarySelect_right_gray"]]);
			}
		maskRight.activeOver = function(){
			chooseColorFrame.subFrameByName(["markSign"]);
			
			backwordButton.changeBgImageTexture([textures["librarySelect_right_blue"]]);
			}
			
		maskRight.activeLeave = function(){
			backwordButton.changeBgImageTexture([textures["librarySelect_right_gray"]]);
			}
			
			
	
	//--------------------------------------------------		
	chooseColorFrame.addFrame([maskLeft,75,5]);
	chooseColorFrame.addFrame([maskRight,610,5]);
	
	maskLeft.changeZ([8]);
	maskRight.changeZ([8]);
	
	
	chooseColorFrame.moveTo([80,30]);
	chooseColorFrame.addActiveNowBy(totalColorUnitFrame);
	
	}
	
//按照方向移动的函数,只适用于选择颜色库
dialog.moveDialogByDirection = function(thisDialogs,xL,yL,tStep,moveBoundary){
	if(!colorFrameMoveTime){
		var n = 0;
		var tStep = !tStep ? 15 : tStep;
		var before = new Array;
		for (var ii = 0;ii < thisDialogs.length;ii++){
			before.push([thisDialogs[ii].x,thisDialogs[ii].y]);
			}
		
		colorFrameMoveTime = setInterval(function(){dialog._moveDialogSteps(thisDialogs,before,xL,yL,n,tStep,moveBoundary);n++;},10);
		}
	}
	
dialog._moveDialogSteps = function(thisDialogs,before,xL,yL,n,tStep,moveBoundary){
	for(var ii =0;ii < thisDialogs.length;ii++){
		var afterX = before[ii][0]+xL*Math.sin(n*PI/2/tStep);
		thisDialogs[ii].x = afterX;
		
		if(xL < 0){
			if(ii == colorLibraryStart-1-moveBoundary){
				if(xL*Math.sin(n*PI/2/tStep)>-30){
					thisDialogs[ii].loseActive();
					}else if(xL*Math.sin(n*PI/2/tStep)<-30 && xL*Math.sin(n*PI/2/tStep)> -50){
						thisDialogs[ii].activeChildByName("longColorItem0",["changeFrameAlpha",[0]]);
						}else if(xL*Math.sin(n*PI/2/tStep)< -50 && xL*Math.sin(n*PI/2/tStep)> -70){
							thisDialogs[ii].activeChildByName("longColorItem1",["changeFrameAlpha",[0]]);
							}else if(xL*Math.sin(n*PI/2/tStep)< -70){
							thisDialogs[ii].activeChildByName("longColorItem2",["changeFrameAlpha",[0]]);
								}
					}else if(ii == colorLibraryStart+6-moveBoundary){
							if( xL*Math.sin(n*PI/2/tStep)> -30){
								thisDialogs[ii].activeChildByName("longColorItem0",["changeFrameAlpha",[1]]);
								}else if(xL*Math.sin(n*PI/2/tStep)< -30 && xL*Math.sin(n*PI/2/tStep)> -50){
									thisDialogs[ii].activeChildByName("longColorItem1",["changeFrameAlpha",[1]]);
									}else if(xL*Math.sin(n*PI/2/tStep)< -50 && xL*Math.sin(n*PI/2/tStep)> -70){
										thisDialogs[ii].activeChildByName("longColorItem2",["changeFrameAlpha",[1]]);
										}else if(xL*Math.sin(n*PI/2/tStep)< -70){
											thisDialogs[ii].getActive();
											}
						}
		}
		if(xL>0){
			if(ii == colorLibraryStart){
				if(xL*Math.sin(n*PI/2/tStep) < 30 ){
					thisDialogs[ii].activeChildByName("longColorItem2",["changeFrameAlpha",[1]]);
					}else if(xL*Math.sin(n*PI/2/tStep)>30 && xL*Math.sin(n*PI/2/tStep) < 50){
						thisDialogs[ii].activeChildByName("longColorItem1",["changeFrameAlpha",[1]]);
						}else if(xL*Math.sin(n*PI/2/tStep)>50 && xL*Math.sin(n*PI/2/tStep) < 70){
							thisDialogs[ii].activeChildByName("longColorItem0",["changeFrameAlpha",[1]]);
							}else if(xL*Math.sin(n*PI/2/tStep)>70){
								thisDialogs[ii].getActive();
								}
				}else if(ii == colorLibraryStart+7){
					if(xL*Math.sin(n*PI/2/tStep) < 30){
						thisDialogs[ii].loseActive();
						}if(xL*Math.sin(n*PI/2/tStep)>30 && xL*Math.sin(n*PI/2/tStep) < 50){
						thisDialogs[ii].activeChildByName("longColorItem2",["changeFrameAlpha",[0]]);
						}else if(xL*Math.sin(n*PI/2/tStep)>50 && xL*Math.sin(n*PI/2/tStep) < 65){
							thisDialogs[ii].activeChildByName("longColorItem1",["changeFrameAlpha",[0]]);
							}else if(xL*Math.sin(n*PI/2/tStep)>65){
								thisDialogs[ii].activeChildByName("longColorItem0",["changeFrameAlpha",[0]]);
								}
					}
			}
		
		var afterY = before[ii][1]+yL*Math.sin(n*PI/2/tStep);
		thisDialogs[ii].y = afterY;
		thisDialogs[ii].transform.identity();
		thisDialogs[ii].transform.translate(afterX,afterY,thisDialogs[ii].z);
		if (n>=tStep){
			clearInterval(colorFrameMoveTime);
			colorFrameMoveTime = null;
			}
		}
	}
		
/////////////////////////////////////////////////////////////////////////////////////		

//按照名字减去子对话框。以后放在dialog.js中。
dialog.frame.prototype.subFrameByName = function(Param){
	var subChildName = Param[0];
	for(var n=0;n < this.child.length;n++){
		if(this.child[n].child[0]){
			this.child[n].subFrameByName([subChildName])
			}
		
		if(subChildName == this.child[n].name){
			this.child[n].transform.parent = null;
			dialog.removeDialog(this.child[n]);
			this.child.splice(n,1);
			n--;
			}
		}
	}

//按照名字找到子对话框。以后放在dialog.js中。因为不唯一，要返回一个数组
dialog.frame.prototype.findFrameByName = function(Param){
	var subChildName = Param[0];
	var childArray = new Array;
	for(var n=0;n < this.child.length;n++){
		if(this.child[n].child[0]){
			this.child[n].findFrameByName([subChildName])
			}
		if(subChildName == this.child[n].name){
			childArray.push(this.child[n]);
			}
		}
		return childArray;
	}

//找到最最父级的函数
dialog.findTheTopParent = function(aChild){
	var thisChildTopParent = aChild;
	if (aChild.parent){
		thisChildTopParent = dialog.findTheTopParent(aChild.parent);
		}
	return thisChildTopParent;
	}
	
	
////////////////////创建鼠标样式/////////////////////////////////////////

dialog.createcustomizeCursor = function(color){
	
	customizeCursor = new dialog.frame("brushColor",[],[],[[],25,25],[]);
	
	var brushColor0 = new dialog.frame("brushColor",[],[],[color,5,2],[]);
	var brushColor1 = new dialog.frame("brushColor",[],[],[color,9,9],[]);
	var brushColor2 = new dialog.frame("brushColor",[],[],[color,3,8],[]);
	//var brushColor3 = new dialog.frame("brushColor",[],[],[color,2,3],[]);

	var bruchCover = new dialog.frame("bruchCover",[],[textures["brush"]],[],[]);
	
	customizeCursor.addFrame([brushColor0,7,1]);
	customizeCursor.addFrame([brushColor1,5,3]);
	customizeCursor.addFrame([brushColor2,2,6]);
	//customizeCursor.addFrame([brushColor3,1,19]);
	customizeCursor.addFrame([bruchCover,0,0]);
	
	customizeCursor.changeZ([5000]);
	
	}







		